/*
 * @Author: ZhanXie
 * @Date: 2020-01-06 09:27:17
 * @LastEditors  : ZhanXie
 * @LastEditTime : 2020-01-06 11:56:53
 * @Description: 
 * @FilePath: /projectStudy/jumpGame/src/game/controller.js
 */
import gameView from './view'
import gameModel from './model'

class GameController {
  constructor() {
    this.gameView = gameView
    this.gameModel = gameModel
    this.gameModel.stageChange.attach((sender, args) => {
      const stageName = args.stage
      switch (stageName) {
        case 'game-over':
          this.gameView.showGameOverPage()
          break
        case 'game':
          this.gameView.showGamePage()
          break
        default:
          return
      }
    })
  }

  // /**
  //  * 显示游戏结束页面
  //  */
  // showGameOverPage = () => {
  //   this.gameView.showGameOverPage()
  // }

  // /**
  //  * 重新开始游戏
  //  */
  // restartGame = () => {
  //   this.gameView.restartGame()
  // }

  /**
   * 初始化所有 view
   * 逻辑控制 view 里的函数能力
   */
  initPages() {
    const gamePageCallbacks = {
      showGameOverPage: () => {
        this.gameModel.setStage('game-over')
      }
    }
    const gameOverPageCallback = {
      gameRestart: () => {
        this.gameModel.setStage('game')
      }
    }
    this.gameView.initGamePage(gamePageCallbacks)
    this.gameView.initGameOverPage(gameOverPageCallback)
  }
}

export default new GameController()